#pragma once
#ifndef __LIT__FILE__PATH__HH__
#define __LIT__FILE__PATH__HH__

#include <LitForward.hpp>
#include <LitString.h>

namespace Lit
{
	typedef StringVector		FilePathVector;
	
	enum FilePathType
	{
		FPT_INVALID = 0,
		FPT_FILE,
		FPT_DIRECTORY,
		FPT_SYMLINK
	};
	enum FilePathAttribute
	{
		FPA_ARCHIVE = 1<<1,					/*!< A file or directory that is an archive file or directory. Applications typically use this attribute to mark files for backup or removal. */
		FPA_HIDDEN = 1<<2,					/*!< The file or directory is hidden. It is not included in an ordinary directory listing. */
		FPA_NORMAL = 1<<3,					/*!< A file that does not have other attributes set. This attribute is valid only when used alone. */
		FPA_NOT_CONTENT_INDEXED = 1<<4,		/*!< The file or directory is not to be indexed by the content indexing service. */
		FPA_OFFLINE  = 1<<4,				/*!< The data of a file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is the hierarchical storage management software. Applications should not arbitrarily change this attribute. */
		FPA_READONLY = 1<<6,				/*!< A file that is read-only. Applications can read the file, but cannot write to it or delete it. This attribute is not honored on directories. For more information, see "You cannot view or change the Read-only or the System attributes of folders in Windows Server 2003, in Windows XP, or in Windows Vista. */
		FPA_SYSTEM  = 1<<8,					/*!< A file or directory that the operating system uses a part of, or uses exclusively. */
		FPA_TEMPORARY = 1<<7				/*!< A file that is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is available, because typically, an application deletes a temporary file after the handle is closed. In that scenario, the system can entirely avoid writing the data. Otherwise, the data is written after the handle is closed. */
	};

	struct LIT_API FilePath
	{
		String p;
	public:
		FilePath( );
		FilePath( const String &path );
		FilePath( const String::char_type* path );
		FilePath( const FilePath& path );
		~FilePath();
		
		FilePathVector listDirectory( FilePathType filter_type = FPT_INVALID, const FilePath &path_ = "", bool recurse_into_subdirs=true, FilePathVector * recurse_vec = NULL ) const;
		FilePathType getType() const;

		bool isFile() const;
		bool isDirectory() const;
		bool isSymLink() const;
		
		bool empty() const;
		String str() const;

		bool hasTrailingSlash() const;
		void setTrailingSlash( bool state );

		bool exists() const;
		FilePath parent() const;
		void sanitise();
		
		String extension() const;
		String fileName( bool with_ext = true ) const;
		String dirName() const;
		
		size_t size() const;
		bool startsWith( const FilePath & path ) const;
		bool endsWith( const FilePath & path ) const;
		bool contains( const FilePath & path ) const;
		String removeIfFound( const FilePath & rem_path ) const;

		void make();

		FilePath& FilePath::operator = ( const FilePath& rk );
		FilePath& FilePath::operator = ( const String& rk );
		
		FilePath operator + ( const FilePath& rk ) const;
		FilePath& operator += ( const FilePath& rk );

		FilePath operator + ( const String& rk ) const;
		FilePath& operator += ( const String& rk );

		FilePath operator + ( const char * str ) const;
		FilePath& operator += ( const char * str );
		
		operator String();
	};

};

#ifndef LIT_CPP
extern "C"
{
#endif
	LIT_API std::ostream&  operator<<( std::ostream& strm, const Lit::FilePath &str );
#ifndef LIT_CPP
};
#endif


#endif